<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;

/**
 * @property int $id 
 * @property int $shop_id 
 * @property string $name 
 * @property string $radio 
 * @property int $is_show
 * @property int $type 
 * @property string $ad_no 
 * @property int $product_id 
 */
class FlyShopAd extends CloudBase
{
    use  SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_shop_ad';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'string', 'shop_id' => 'string', 'is_show' => 'integer', 'type' => 'integer', 'product_id' => 'string'];

    public function product_info()
    {
        $fields = ['id','shop_id','product_name'];
        return $this->belongsTo(Product::class, 'product_id' ,'id')
            ->with('sku_list')
            ->with('main_pic')
            ->select($fields);
    }

    public function commissions()
    {
        return $this->hasMany(FlyOrderProduct::class, 'product_id' ,'product_id')
            ->where('fly_order_product.moments_id','!=','0')
            ->leftJoin('fly_order_commissions as foc','foc.order_id','=','fly_order_product.order_id')
            ->select(['foc.*','fly_order_product.order_id','fly_order_product.product_id','fly_order_product.subtotal as pt'])
            ;
    }

    public function commissions_order()
    {
        return $this->hasMany(FlyOrderProduct::class, 'product_id' ,'product_id')
            ->where('fly_order_product.moments_id','!=','0')
//            ->leftJoin('fly_order_commissions as foc','foc.order_id','=','fly_order_product.order_id')
//            ->select(['foc.*','fly_order_product.order_id','fly_order_product.product_id','fly_order_product.subtotal as pt'])
            ;
    }
}